package com.romin.action;

import com.romin.dao.ManagerDao;
import com.romin.pojo.Manager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.Map;

/**
 * @author cloud.eve
 */
@Controller
public class LoginAction {
    @Resource
    private ManagerDao managerDao;

    @RequestMapping("/login")
    public String login(Map<String, Object> model) {
        return "login";
    }

    @RequestMapping("/logininfo")
    @ResponseBody
    public Manager loginInfo(Principal principal) {
        Manager manager = null;
        if(principal!=null&&principal.getName()!=null){
            manager = managerDao.findByUserName(principal.getName());
            manager.setPassword(null);
        }
        return manager;
    }
    @RequestMapping("/register")
    public String register(Manager manager) {
        manager.setAccessType(0);
        managerDao.save(manager);
        return "login";
    }
}
